<?php

/**
 * EmailTemplate form base class.
 *
 * @method EmailTemplate getObject() Returns the current form's model object
 *
 * @package    ecollegeplus
 * @subpackage form
 * @author     Batanayi Matuku
 * @version    SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
 */
abstract class BaseEmailTemplateForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'id'          => new sfWidgetFormInputHidden(),
      'name'        => new sfWidgetFormInputText(),
      'subject'     => new sfWidgetFormTextarea(),
      'description' => new sfWidgetFormTextarea(),
      'body'        => new sfWidgetFormTextarea(),
      'from_email'  => new sfWidgetFormTextarea(),
      'to_email'    => new sfWidgetFormTextarea(),
      'cc_email'    => new sfWidgetFormTextarea(),
      'bcc_email'   => new sfWidgetFormTextarea(),
      'reply_to'    => new sfWidgetFormTextarea(),
      'is_html'     => new sfWidgetFormInputCheckbox(),
      'is_active'   => new sfWidgetFormInputCheckbox(),
      'created_at'  => new sfWidgetFormDateTime(),
      'updated_at'  => new sfWidgetFormDateTime(),
      'slug'        => new sfWidgetFormInputText(),
    ));

    $this->setValidators(array(
      'id'          => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'name'        => new sfValidatorString(array('max_length' => 255)),
      'subject'     => new sfValidatorString(array('max_length' => 5000)),
      'description' => new sfValidatorString(array('max_length' => 5000, 'required' => false)),
      'body'        => new sfValidatorString(),
      'from_email'  => new sfValidatorString(array('max_length' => 5000)),
      'to_email'    => new sfValidatorString(array('max_length' => 5000, 'required' => false)),
      'cc_email'    => new sfValidatorString(array('max_length' => 5000, 'required' => false)),
      'bcc_email'   => new sfValidatorString(array('max_length' => 5000, 'required' => false)),
      'reply_to'    => new sfValidatorString(array('max_length' => 5000)),
      'is_html'     => new sfValidatorBoolean(array('required' => false)),
      'is_active'   => new sfValidatorBoolean(array('required' => false)),
      'created_at'  => new sfValidatorDateTime(),
      'updated_at'  => new sfValidatorDateTime(),
      'slug'        => new sfValidatorString(array('max_length' => 255, 'required' => false)),
    ));

    $this->validatorSchema->setPostValidator(
      new sfValidatorAnd(array(
        new sfValidatorDoctrineUnique(array('model' => 'EmailTemplate', 'column' => array('name'))),
        new sfValidatorDoctrineUnique(array('model' => 'EmailTemplate', 'column' => array('slug', 'name'))),
      ))
    );

    $this->widgetSchema->setNameFormat('email_template[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function getModelName()
  {
    return 'EmailTemplate';
  }

}
